package com.linkai.JUC._07_queue;

import java.awt.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.LockSupport;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Description: 阻塞队列 BlockingQueue；一般用于生产设消费者模式，和前面 _02_pc 联系起来看
 *                https://www.jb51.net/article/75986.htm
 *                https://github.com/JetBrains/jdk8u_hotspot/blob/master/src/os/linux/vm/os_linux.cpp
 * @Author: 林凯
 * @Date: 2021/11/5 0:58
 */
public class ArrayBlockingQueueDemo {

    public void test() {
        LockSupport.park(this);
    }

    public static void main(String[] args) throws InterruptedException {
        ArrayBlockingQueueDemo demo = new ArrayBlockingQueueDemo();
//        demo.test();
        // wait 必须放在同步代码块里面使用，不然就会报错
        // 因为 wait 会释放锁，前提是必须要获得锁才能够释放
        try {
            demo.wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
//        Lock reentrantLock = new ReentrantLock();
//        reentrantLock.wait();

        System.out.println("test over");
        BlockingQueue arrayBlockingQueue = new ArrayBlockingQueue(10);
        BlockingQueue linkedBlockingQueue = new LinkedBlockingQueue();
    }
}
